﻿using System;
using System.Web;
using System.Data;

namespace msBsc.WebUi
{
    public partial class wfMyTradingLog : msBsc.Cls.BPCustom
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindControls();
                dodoloadlist("", "", "", "", "");
            }

        }
        private void BindControls()
        {
            if (!IsPostBack)
            { 
            }
        }
        private void dodoloadlist(string strDtStart, string strDtEnd
            , string CurrPageNum, string strPageRowsCount, string strSort)
        {
            using (msBsc.AppLogic.DataAlc.CBizShpOrderRate oCDbAccess = new msBsc.AppLogic.DataAlc.CBizShpOrderRate())
            {
                string strSql = @"
    SELECT
    A.* 
    FROM SHP_SCORE_TRADING_LOG A  
    WHERE
    (A.ACCOUNT_NO='" + msBsc.SvRef.UserInfo.Operator + @"')
    ";
                if (strDtStart != string.Empty)
                {
                    strSql += " AND A.INITIAL_DT >='" + strDtStart + " 00:00:00'";
                }
                if (strDtEnd != string.Empty)
                {
                    strSql += " AND A.INITIAL_DT <= '" + strDtEnd + " 23:59:59'";
                }

                DataSet ds = oCDbAccess.DataObj.QueryBySQL(strSql);
                string strjsontem1 = msBsc.AppLogic.Cfg.HttpTools.GetJsonByTable(ds.Tables[0], "", ""
                    , (CurrPageNum == string.Empty ? 1 : int.Parse(CurrPageNum))
                    , (strPageRowsCount == string.Empty ? 20 : int.Parse(strPageRowsCount))
                    , (strSort == string.Empty ? "INITIAL_DT ASC" : strSort));
                this.ExecJScript(@" var data= " + strjsontem1 + @" ; 
                updateTableHtml( data);");
            }

            using (msBsc.AppLogic.DataAlc.CBizShpCustomerInfo ouinfo = new AppLogic.DataAlc.CBizShpCustomerInfo())
            {
                this.ExecJScript("$('#J_SmallTotal').html('"+ouinfo.GetUserScoreAllowUseQty(msBsc.SvRef.UserInfo.Operator).ToString()+"');");
            }
        }


        public override void DoAction()
        {
            if (this.strAction == "doloadlist")
            {
                dodoloadlist(this.GetParamHtValue("INITIAL_DT_S")
                    , this.GetParamHtValue("INITIAL_DT_E")
                    , this.GetParamHtValue("NEW_PAGE_NUM")
                    , this.GetParamHtValue("PAGE_ROW_COUNT")
                    , this.GetParamHtValue("PAGE_ROW_SORT"));
            }
            else if (this.strAction == "seekcanuseqty")
            {
                using (msBsc.AppLogic.DataAlc.CBizShpScoreCard objlog = new AppLogic.DataAlc.CBizShpScoreCard())
                {
                    DataSet dstm3 = objlog.DataObj.QueryBySQL("SELECT SCORE_QTY FROM SHP_SCORE_CARD WHERE  ( SCORE_CARD_NO ='" + this.GetParamHtValue("txtScoreCardNo") + "') ");
                    if (dstm3.Tables[0].Rows.Count > 0)
                    {
                        this.ExecJScript("$('#spnSetScoreQty').html('" + dstm3.Tables[0].Rows[0]["SCORE_QTY"].ToString() + "');");
                    }
                    else
                    {
                        this.ExecJScript("$('#spnSetScoreQty').html('0');");
                    }
                }
            }
            else if (this.strAction == "dochongzhi")
            {  
                System.Transactions.TransactionOptions transactionOption = new System.Transactions.TransactionOptions();
                transactionOption.IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted;
                transactionOption.Timeout = new TimeSpan(0, 10, 0);
                using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope(System.Transactions.TransactionScopeOption.Required, transactionOption))
                {
                    using (msBsc.AppLogic.DataAlc.CBizShpScoreCard objlog = new AppLogic.DataAlc.CBizShpScoreCard())
                    {
                        objlog.UseScoreCard(this.GetParamHtValue("txtScoreCardNo"));

                        this.ExecJScript("layerform && layer.close(layerform);loadlist();");
                    }
                    ts.Complete();
                }
            } 
        }
    }
}